//
//  UIViewController+jumpAdd.m
//

#import "UIViewController+jumpAdd.h"


@implementation UIViewController (jumpAdd)
/**
 *  @author 赵继申, 16-04-12 14:04:20
 *
 *  跳转
 *
 *  @param className  目标类名
 *  @param parameters 参数
 */
-(void)jumpNextViewController:(NSString*)className parameters:(id)parameters {
    [self jumpNextViewController:className parameters:parameters animated:YES];
}

-(void)jumpNextViewController:(NSString*)className parameters:(id)parameters animated:(BOOL)animated{
    Class class = NSClassFromString(className);
    if(!class){
        return;
    }
    NSArray *array = self.navigationController.viewControllers;
    if ([array[array.count - 1] isMemberOfClass:class]) {
        return;
    }
    UIViewController *next = [[class alloc] init];
    if (parameters != nil) {
        NSMutableDictionary *dic = nil;
        if (![parameters isKindOfClass:[NSDictionary class]]) {
            dic = [NSMutableDictionary dictionaryWithDictionary:[parameters properties_aps]];
        }else{
            dic = [NSMutableDictionary dictionaryWithDictionary:parameters];
        }
        NSArray *pro = [next getAllProperties];
        for (NSString *key in pro) {
            if ([[dic allKeys] containsObject:key] ) {
                [next setValue:dic[key] forKey:key];
            }
            
        }
    }
    
    [self.navigationController pushViewController:next animated:animated];
}


@end
